<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item prop="outQuaName">
        <el-input
          v-model="queryParams.outQuaName"
          placeholder="请输入检验单编号/名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="outQuaProduct">
        <el-input
          v-model="queryParams.outQuaProduct"
          placeholder="请输入质检产品"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="outQuaPeo">
        <el-input
          v-model="queryParams.outQuaPeo"
          placeholder="请输入检验人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="outQuaBatch">
        <el-input
          v-model="queryParams.outQuaBatch"
          placeholder="请输入工单批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="outQuaCheckDate">
        <el-date-picker clearable
                        v-model="queryParams.outQuaCheckDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择检验日期"
                        style="width: 205px !important;"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="outQuaDate">
        <el-date-picker clearable
                        v-model="queryParams.outQuaDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择发货日期"
                        style="width: 205px !important;"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item prop="outQuaResult">
        <el-select v-model="queryParams.outQuaResult" placeholder="请选择质检结果" clearable>
          <el-option
            v-for="dict in getQualityYesNo"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item style="width: calc(100% - 235px); text-align: right">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="'/qc/outgoing-quality-change'" class="link-type">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['qc:outgoingQuality:add']"
          >新增
          </el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['qc:outgoingQuality:edit']"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['qc:outgoingQuality:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['qc:outgoingQuality:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="outgoingQualityList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" fixed />
      <el-table-column type="index" align="center" label="序号" fixed />
      <el-table-column label="检验单名称" align="center" prop="outQuaName" width="120" fixed show-overflow-tooltip />
      <el-table-column label="检验单编号" align="center" prop="outQuaCode" width="150" fixed show-overflow-tooltip />
      <el-table-column label="产品编号" align="center" prop="outQuaProduct" width="150" show-overflow-tooltip />
      <el-table-column label="规格型号" align="center" prop="gbsGood.pdSpecType" width="100" show-overflow-tooltip />
      <el-table-column label="单位" align="center" prop="gbsGood.gbsGoodUnit.guName" width="100"
                       show-overflow-tooltip
      />
      <el-table-column label="批次号" align="center" prop="outQuaProduct" width="100" show-overflow-tooltip />
      <el-table-column label="发货日期" align="center" prop="outQuaDate" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outQuaDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验日期" align="center" prop="outQuaCheckDate" width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.outQuaCheckDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检验人" align="center" prop="outQuaPeoName" show-overflow-tooltip />
      <el-table-column label="质检数量" align="center" prop="outQuaNum" show-overflow-tooltip />
      <el-table-column label="合格数量" align="center" prop="outQuaGood" show-overflow-tooltip />
      <el-table-column label="批次号" align="center" prop="outQuaBatch" show-overflow-tooltip />
      <el-table-column label="质检结果" align="center" prop="outQuaResult" fixed="right" width="100">
        <template slot-scope="scope">
          <dict-tag :options="getQualityYesNo" :value="scope.row.outQuaResult" />
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="160">
        <template slot-scope="scope">
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['qc:outgoingQuality:edit']"-->
<!--          >修改-->
<!--          </el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['qc:outgoingQuality:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { delOutgoingQuality, listOutgoingQuality } from '@/api/yyj/qc/outgoingQuality'
import { parseTime } from '@/utils/ruoyi'

export default {
  name: 'OutgoingQuality',
  dicts: ['qc_quality_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 出货检验单表格数据
      outgoingQualityList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        outQuaName: null,
        outQuaDate: null,
        outQuaCheckDate: null,
        outQuaPeo: null,
        outQuaPeoName: null,
        outQuaNum: null,
        outQuaGood: null,
        outQuaResult: null,
        outQuaProduct: null,
        outQuaBatch: null,
        outQuaDesc: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        outQuaName: [
          { required: true, message: '检验单名称不能为空', trigger: 'blur' }
        ],
        outQuaDate: [
          { required: true, message: '发货日期不能为空', trigger: 'blur' }
        ],
        outQuaCheckDate: [
          { required: true, message: '检验日期不能为空', trigger: 'blur' }
        ],
        outQuaPeo: [
          { required: true, message: '检验人不能为空', trigger: 'blur' }
        ],
        outQuaNum: [
          { required: true, message: '质检数量不能为空', trigger: 'blur' }
        ],
        outQuaGood: [
          { required: true, message: '合格数量不能为空', trigger: 'blur' }
        ],
        outQuaResult: [
          { required: true, message: '质检结果 1 合格 0 不合格不能为空', trigger: 'change' }
        ],
        outQuaProduct: [
          { required: true, message: '质检产品不能为空', trigger: 'blur' }
        ],
        outQuaBatch: [
          { required: true, message: '质检批次号不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  computed: {
    getQualityYesNo() {
      return this.dict.type.qc_quality_yes_no
    }
  },
  methods: {
    parseTime,
    /** 查询出货检验单列表 */
    getList() {
      this.loading = true
      listOutgoingQuality(this.queryParams).then(response => {
        this.outgoingQualityList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.outQuaCode)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加出货检验单'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const outQuaCode = row.outQuaCode || this.ids
      this.$router.push({
        path: `/qc/outgoing-quality-change/${outQuaCode}`
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const outQuaCodes = row.outQuaCode || this.ids
      this.$modal.confirm('是否确认删除出货检验单编号为"' + outQuaCodes + '"的数据项？').then(function() {
        return delOutgoingQuality(outQuaCodes)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('qc/outgoingQuality/export', {
        ...this.queryParams
      }, `outgoingQuality_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
